package org.dochandler.service.core;

import java.util.List;

import org.dochandler.dao.MissionRequestDAO;
import org.dochandler.service.MissionRequestService;
import org.dochandler.service.domain.Criteria;
import org.dochandler.service.domain.Officer;
import org.dochandler.service.domain.annotation.CommandersOnly;
import org.dochandler.service.domain.annotation.TopSecretDocCreation;
import org.dochandler.service.domain.annotation.WorkingTime;
import org.dochandler.service.domain.mission.MissionRequest;
import org.esfinge.guardian.utils.ServiceLocator;

public class MissionRequestServiceCore implements MissionRequestService {
	
	private MissionRequestDAO missionRequestDao;
	private Officer officer;
	
	public MissionRequestServiceCore(Officer officer) {
		setOfficer(officer);
		setMissionRequestDao(ServiceLocator.getServiceImplementation(MissionRequestDAO.class));
	}
	
	@Override
	public Boolean create(MissionRequest request) {
		return (requestMission(request) != null);
	}

	@Override
	public MissionRequest read(Long documentId) {
		return getMissionRequestDao().findById(documentId);
	}

	@Override
	public Boolean delete(Long documentId) {
		return getMissionRequestDao().delete(documentId);
	}

	@Override
	public Boolean edit(MissionRequest request) {
		return getMissionRequestDao().update(request);
	}

	@Override
	public List<MissionRequest> listAll() {
		return getMissionRequestDao().findAll();
	}

	@Override
	public List<MissionRequest> listByCriteria(Criteria<?> criteria) {
		return null;
	}

	@Override
	@TopSecretDocCreation
	@CommandersOnly
	@WorkingTime
	public Long requestMission(MissionRequest request) {
		return getMissionRequestDao().createMission(request);
	}
	
	/*
	 * SETTERS AND GETTERS
	 */
	
	public MissionRequestDAO getMissionRequestDao() {
		return missionRequestDao;
	}

	public void setMissionRequestDao(MissionRequestDAO missionRequestDao) {
		this.missionRequestDao = missionRequestDao;
	}
	
	public Officer getOfficer() {
		return officer;
	}

	public void setOfficer(Officer officer) {
		this.officer = officer;
	}

}
